package servlet;

import mapper.StudentMapper;
import org.apache.ibatis.session.SqlSession;
import pojo.Student;
import utils.MybatisUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @Author leiHua
 * @Date 2022/11/24 16:47
 */
@WebServlet("/ShowAllStudentsServlet")
public class ShowAllStudentsServlet extends HttpServlet {
    //session :allStudents

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<Student> students = mapper.selectAllStudent();
        HttpSession session = req.getSession();
        session.setAttribute("allStudents",students);
        req.getRequestDispatcher("showAllStudents.jsp").forward(req,resp);
    }
}
